package com.to.aboomy.bannersample.pagetransformer;

import com.to.aboomy.banner.BannerViewPager;
import ohos.agp.components.Component;

/**
 * @author xujianhong
 * @since 2021-08-06
 */
public class RotateUpTransformer implements BannerViewPager.PageTransformer {
    private final float ROT_MOD = -15.0F;
    @Override
    public void transformerPage(BannerViewPager.PageType pageType, Component page, float offset, float offsetPixels) {
        float width = (float)page.getWidth();
        float rotation = 0F;
        switch (pageType) {
            case PREVIOUS:
                if (offsetPixels < 0) {
                    offset = 1 - offset;
                    rotation = ROT_MOD * offset;
                    page.setPivotX(width * 0.5F);
                    page.setPivotY(0.0F);
                    page.setTranslationX(0.0F);

                    if (offsetPixels < 0) {
                        page.setRotation(-rotation);
                    }
                }
                break;
            case CURRENT:
                rotation = ROT_MOD * offset;
                page.setPivotX(width * 0.5F);
                page.setPivotY(0.0F);
                page.setTranslationX(0.0F);
                if (offsetPixels >= 0) {
                    page.setRotation(-rotation);
                }else{
                    page.setRotation(rotation);
                }
                break;

            case NEXT:
                offset = 1 - offset;
                rotation = ROT_MOD * offset;
                page.setPivotX(width * 0.5F);
                page.setPivotY(0.0F);
                page.setTranslationX(0.0F);

                if (offsetPixels >= 0) {
                    page.setRotation(rotation);
                }

                break;

            case OTHER:
                page.setPivotX(1F);
                page.setPivotY(1F);
                page.setRotation(0F);
                break;
        }
    }
}
